package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    @Autowired
    ItemMapper itemMapper;

    @Override
    public PageDTO<Item> pageList(Integer page, Integer size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("update_time");
        IPage<Item> p =new Page<>(page,size);
        itemMapper.selectPage(p,queryWrapper);
        PageDTO<Item> pageDTO = new PageDTO();
        pageDTO.setTotal(p.getTotal());
        pageDTO.setList(p.getRecords());
        return pageDTO;
    }

    @Override
    public void delete(Long id) {
        itemMapper.deleteById(id);
    }


}
